//
//  EpointFrameDB.m
//  EpointFrame5
//
//  Created by 李亚春 on 13-12-17.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "EpointFrameDB.h"

@implementation EpointFrameDB

- (id)init {
    self = [super init];
    if (self) {
        sqlite3_open([[EpointFrameDB getFrameDBFilePath] UTF8String],&database);
        [self createTable:"create table if not exists frame_config(key text,value text)"];
        [self createTable:"create table if not exists user(loginid text,userguid text,ouguid text,displayname text,mobile text,telephoneoffice text,title text,description text,fax text,sex text,email text,telephonehome text,shortmobile text,qqnumber text,ntxextnumber text,namepyshou text)"];
        [self createTable:"create table if not exists ou(ouguid text,ouname text,parentguid text,namepyshou text)"];
        [self createTable:"create table if not exists webinfo_category(CategoryName text,CategoryGuid text,ParentCategoryGuid text,IsTongzhiGongGao text)"];
        [self createTable:"create table if not exists frame_res(key text,value blob)"];
//        [self createTable:"create table if not exists frame_attach(filename text,savetime text,fromtype text,fromtitle text,filepath text,filelength text,filetype text,url text)"];
    }
    return self;
}

//建表操作
-(void)createTable:(char *)sql
{
    char *errorMsg;
    sqlite3_exec(database, sql, NULL, NULL, &errorMsg);
    if (errorMsg!=NULL) {
        NSLog(@"ERR:%s",errorMsg);
    }
}

+(NSString *)getFrameDBFilePath
{
    NSArray *documentsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *dbFilePath = [[documentsPaths objectAtIndex:0]stringByAppendingPathComponent:@"EpointFrameDB"];
    return dbFilePath;
}

+(sqlite3*)getFrameDB
{
    sqlite3 *framedb;
    sqlite3_open([[EpointFrameDB getFrameDBFilePath] UTF8String],&framedb);
    return framedb;
}

@end
